package com.ajobs.cloudstream.delay.delaycomponent.binder;

import com.ajobs.cloudstream.delay.delaycomponent.DelayOutPutProducer;
import com.ajobs.pojo.MsgPojo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 *生产者
 *
 *@author weijianxun
 */
@Service
@EnableBinding({DelayOutPutProducer.class})
public class DelayOutputProducerBinder {
    @Autowired
    private DelayOutPutProducer delayOutPutProducer;

    public void sendDelayMessage(String msg) {
        System.out.println(new Date());
        MsgPojo msgPojo = new MsgPojo();
        msgPojo.setMsg(msg);
        delayOutPutProducer.delayOutput().send(MessageBuilder.withPayload(msgPojo).setHeader("x-delay", 3000).build());
    }
}
